package com.ruoyi.work.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.work.domain.WorkSeal;
import com.ruoyi.work.mapper.WorkSealMapper;
import com.ruoyi.work.service.IWorkSealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 印章管理Service业务层处理
 *
 * @author fengcheng
 * @date 2025-03-17
 */
@Service
public class WorkSealServiceImpl implements IWorkSealService {
    @Autowired
    private WorkSealMapper workSealMapper;

    /**
     * 查询印章管理
     *
     * @param suraId 印章管理主键
     * @return 印章管理
     */
    @Override
    public WorkSeal selectWorkSealBySuraId(Long suraId) {
        return workSealMapper.selectWorkSealBySuraId(suraId);
    }

    /**
     * 查询印章管理列表
     *
     * @param workSeal 印章管理
     * @return 印章管理
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<WorkSeal> selectWorkSealList(WorkSeal workSeal) {
        return workSealMapper.selectWorkSealList(workSeal);
    }

    /**
     * 新增印章管理
     *
     * @param workSeal 印章管理
     * @return 结果
     */
    @Override
    public int insertWorkSeal(WorkSeal workSeal) {
        workSeal.setUserId(SecurityUtils.getUserId());
        workSeal.setDeptId(SecurityUtils.getDeptId());
        workSeal.setUserName(SecurityUtils.getUsername());
        workSeal.setDeptName(SecurityUtils.getLoginUser().getUser().getDept().getDeptName());
        workSeal.setCreateTime(DateUtils.getNowDate());
        return workSealMapper.insertWorkSeal(workSeal);
    }

    /**
     * 修改印章管理
     *
     * @param workSeal 印章管理
     * @return 结果
     */
    @Override
    public int updateWorkSeal(WorkSeal workSeal) {
        workSeal.setUpdateTime(DateUtils.getNowDate());
        return workSealMapper.updateWorkSeal(workSeal);
    }

    /**
     * 批量删除印章管理
     *
     * @param suraIds 需要删除的印章管理主键
     * @return 结果
     */
    @Override
    public int deleteWorkSealBySuraIds(Long[] suraIds) {
        return workSealMapper.deleteWorkSealBySuraIds(suraIds);
    }

    /**
     * 删除印章管理信息
     *
     * @param suraId 印章管理主键
     * @return 结果
     */
    @Override
    public int deleteWorkSealBySuraId(Long suraId) {
        return workSealMapper.deleteWorkSealBySuraId(suraId);
    }
}
